<?php
namespace Anls\Controller;
use Think\Controller;
use Anls\Com\File;
use Anls\Com\Bar;
use Anls\Com\Strategy;
use Anls\Common;
/**
 * 导入日志记录
 * @author wsf
 *
 */
class ImportLogController extends AbstractTradeSupportController{

    public function exec(){
        // 品种
        $symbolType = 'stock';
        // 周期
        $period = '1day';
        // 获取分析文件
        $fileList = File\FileHandle::getFiles($symbolType,$period);
        $fileListCnt = count($fileList);
    
        // 获取过滤代码
        $filterCodes = $this->getFilterCodes();
        $BarH = new Bar\BarHandle();
         
        for($fi=0;$fi<$fileListCnt;$fi++){
            // 获取文件名
            $fileName = $fileList[$fi];
            // 过滤
            if($filterCodes[$fileName] == 1) continue;
            $this->logKData($fileName);
        }
    }

    public function logKData($code){
        $keys = 'kdata:'.$code.':1day:*';
        $datas = $this->redis_k_db->getKeys($keys);
        $len = count($datas);
        $maxDateNum = -1;
        $maxDate = '';
        $maxDateIndex = 0;
        for($i=0;$i<$len;$i++){
            $data = $datas[$i];
            $_date = str_replace('kdata:'.$code.':1day:', '', $data);
            $_dateNum = str_replace('/', '', $_date);
            if($_dateNum > $maxDateNum) {
                $maxDateNum = $_dateNum;
                $maxDate = $_date;
                $maxDateIndex = $i;
            }
        }
        $_dateArr = explode('/', $maxDate);
        $year = $_dateArr[0];
        $month = $_dateArr[1];
        $day = $_dateArr[2];
        $dateKey = 'kdata:'.$code.':1day:log:Date:';
        $this->redis_k_db_log->set($dateKey.'curNum',$maxDateNum);
        $this->redis_k_db_log->set($dateKey.'cur',$maxDate);
        $this->redis_k_db_log->set($dateKey.'curYear',$year);
        $this->redis_k_db_log->set($dateKey.'curMonth',$month);
        $this->redis_k_db_log->set($dateKey.'curDay',$day);
    }
 
}